<html>
<head><meta charset="utf-8"><title>Generating ExprKind:Err from AST lowering · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Generating.20ExprKind.3AErr.20from.20AST.20lowering.html">Generating ExprKind:Err from AST lowering</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="198732379"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Generating%20ExprKind%3AErr%20from%20AST%20lowering/near/198732379" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Generating.20ExprKind.3AErr.20from.20AST.20lowering.html#198732379">(May 26 2020 at 08:15)</a>:</h4>
<p>In librustc_ast_lowering I turn <code>ast::ExprKind::InlineAsm</code> to <code>hir::ExprKind::Err</code> if the current target doesn't support inline asm or if an invalid register is used for an operand. Unfortunately this seems to lead to crashes later on (<a href="https://github.com/rust-lang/rust/issues/72570">#72570</a>) since the expressions used in the asm operands aren't lowered to HIR and are therefore missing <code>HirId</code>s.</p>



<a name="198732541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Generating%20ExprKind%3AErr%20from%20AST%20lowering/near/198732541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Generating.20ExprKind.3AErr.20from.20AST.20lowering.html#198732541">(May 26 2020 at 08:17)</a>:</h4>
<p>Is it valid to lower something to <code>hir:ExprKind::Err</code>? If not then I guess I have to make up some semi-valid HIR to keep the compiler happy. Until what point do I need to keep this HIR valid?</p>



<a name="198735678"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Generating%20ExprKind%3AErr%20from%20AST%20lowering/near/198735678" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Generating.20ExprKind.3AErr.20from.20AST.20lowering.html#198735678">(May 26 2020 at 08:53)</a>:</h4>
<p>I've encountered the same issue, let me find the PR</p>



<a name="198735770"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Generating%20ExprKind%3AErr%20from%20AST%20lowering/near/198735770" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Generating.20ExprKind.3AErr.20from.20AST.20lowering.html#198735770">(May 26 2020 at 08:54)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/pull/72275">https://github.com/rust-lang/rust/pull/72275</a></p>



<a name="198735925"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Generating%20ExprKind%3AErr%20from%20AST%20lowering/near/198735925" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> marmeladema <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Generating.20ExprKind.3AErr.20from.20AST.20lowering.html#198735925">(May 26 2020 at 08:56)</a>:</h4>
<p>So i did not properly fix the lowering per say, but i ended up to the same conclusion, being that generating <code>hir:ExprKind::Err</code> nodes make the HIR invalid and it breaks/crash later on</p>



<a name="198738649"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Generating%20ExprKind%3AErr%20from%20AST%20lowering/near/198738649" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Generating.20ExprKind.3AErr.20from.20AST.20lowering.html#198738649">(May 26 2020 at 09:29)</a>:</h4>
<p>I think you need to eagerly lower all expressions even if you are throwing them away later</p>



<a name="198738674"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Generating%20ExprKind%3AErr%20from%20AST%20lowering/near/198738674" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Generating.20ExprKind.3AErr.20from.20AST.20lowering.html#198738674">(May 26 2020 at 09:30)</a>:</h4>
<p>but we may be able to come up with a better scheme</p>



<a name="198738751"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Generating%20ExprKind%3AErr%20from%20AST%20lowering/near/198738751" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Generating.20ExprKind.3AErr.20from.20AST.20lowering.html#198738751">(May 26 2020 at 09:30)</a>:</h4>
<p>where are the <code>HirId</code>s to the asm operands? Maybe we need to ensure these ids are never stored anywhere?</p>



<a name="198739454"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Generating%20ExprKind%3AErr%20from%20AST%20lowering/near/198739454" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Generating.20ExprKind.3AErr.20from.20AST.20lowering.html#198739454">(May 26 2020 at 09:40)</a>:</h4>
<p>I haven't managed to get a proper backtrace from the crash yet.</p>



<a name="198739464"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Generating%20ExprKind%3AErr%20from%20AST%20lowering/near/198739464" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Generating.20ExprKind.3AErr.20from.20AST.20lowering.html#198739464">(May 26 2020 at 09:41)</a>:</h4>
<p>Building rustc with debuginfo takes forever :/</p>



<a name="198739810"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Generating%20ExprKind%3AErr%20from%20AST%20lowering/near/198739810" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Generating.20ExprKind.3AErr.20from.20AST.20lowering.html#198739810">(May 26 2020 at 09:45)</a>:</h4>
<p>huh?</p>



<a name="198739949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Generating%20ExprKind%3AErr%20from%20AST%20lowering/near/198739949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Generating.20ExprKind.3AErr.20from.20AST.20lowering.html#198739949">(May 26 2020 at 09:47)</a>:</h4>
<p>I don't remember it taking any additional time</p>



<a name="198739953"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Generating%20ExprKind%3AErr%20from%20AST%20lowering/near/198739953" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Generating.20ExprKind.3AErr.20from.20AST.20lowering.html#198739953">(May 26 2020 at 09:47)</a>:</h4>
<p>did you leave optimizations enabled?</p>



<a name="198740109"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Generating%20ExprKind%3AErr%20from%20AST%20lowering/near/198740109" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Generating.20ExprKind.3AErr.20from.20AST.20lowering.html#198740109">(May 26 2020 at 09:49)</a>:</h4>
<p>Yes, the LTO at the end is the part that takes a while.</p>



<a name="198740287"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Generating%20ExprKind%3AErr%20from%20AST%20lowering/near/198740287" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Generating.20ExprKind.3AErr.20from.20AST.20lowering.html#198740287">(May 26 2020 at 09:51)</a>:</h4>
<p>I'm currently trying to eagerly lower all sub-expressions as you suggest.</p>



<a name="198740528"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Generating%20ExprKind%3AErr%20from%20AST%20lowering/near/198740528" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Generating.20ExprKind.3AErr.20from.20AST.20lowering.html#198740528">(May 26 2020 at 09:54)</a>:</h4>
<p>OK that seems to have solved the issue, thanks!</p>



<a name="198740603"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Generating%20ExprKind%3AErr%20from%20AST%20lowering/near/198740603" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Generating.20ExprKind.3AErr.20from.20AST.20lowering.html#198740603">(May 26 2020 at 09:55)</a>:</h4>
<p>I had some early exit logic on error which I removed. I still emit <code>hir::ExprKind::Err</code> but I now call <code>lower_expr_mut</code> on all sub-expressions.</p>



<a name="198741987"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Generating%20ExprKind%3AErr%20from%20AST%20lowering/near/198741987" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Generating.20ExprKind.3AErr.20from.20AST.20lowering.html#198741987">(May 26 2020 at 10:09)</a>:</h4>
<p><span aria-label="+1" class="emoji emoji-1f44d" role="img" title="+1">:+1:</span> if you have the time please open an issue about this (with the ICE message about the missing <code>HirId</code>, so that people can find it when they hit the same problem). Mentioning the solution and asking for something allowing us to make it simpler to eagerly bail out early.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>